package com.drcoffee.drcoffeemall.controller;

import com.drcoffee.drcoffeemall.entry.Result;
import com.drcoffee.drcoffeemall.service.AfterSaleService;
import com.drcoffee.drcoffeemall.util.SendWxWorkUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/afterSale")
public class AfterSaleController {

    @Autowired
    AfterSaleService afterSaleService;
    @Autowired
    SendWxWorkUtil sendWxWorkUtil;

    /*
     * 售后单审核
     * */
    @GetMapping("/examineAfterSale")
    public Result examineAfterSale(@RequestHeader String Token, @RequestParam String code, @RequestParam Integer examiner, @RequestParam(required = false) String remark) {
        String sql = ",flow_one = ";
        if (examiner == 1) { // 通过
            return afterSaleService.setAfterSaleStatus(Token, code, 2, sql);
        } else { // 未通过
            String new_remark = "【审核未通过】" + remark;
            return afterSaleService.setAfterSaleStatusTwo(Token, code, 2, new_remark, sql);
        }
    }


    @PostMapping("/getAfterSaleByStatus")
    public ResponseEntity<Map<String, Object>> getAfterSaleByStatus(@RequestBody Map<String, Object> paramMap) {
        return afterSaleService.getAfterSaleByStatus(paramMap);
    }


    /*
     * 验收
     * */
    @GetMapping("/AccAfterSale")
    public Result AccAfterSale(@RequestHeader String Token, @RequestParam String code) {
        String sql = ",flow_two = ";
        return afterSaleService.setAfterSaleStatus(Token, code, 4, sql);
    }


    /*
     * 退款审核
     * */
    @GetMapping("refundFlowThree")
    public Result refundFlowThree(@RequestHeader String Token, @RequestParam String code) {
        String sql = ",flow_three = ";
        return afterSaleService.setAfterSaleStatus(Token, code, 5, sql);
    }

    /*
     * 售后单审核
     * */
    @GetMapping("/refundReview")
    public Result refundReview(@RequestHeader String Token, @RequestParam String code, @RequestParam Integer status) {
        String sql = ",flow_three = ";
        return afterSaleService.setAfterSaleStatus(Token, code, status, sql);
    }


    /*
     * 退款执行
     * */
    @GetMapping("refundFlowFour")
    public Result refundFlowFour(@RequestHeader String Token, @RequestParam String code) {
        return afterSaleService.refundFlowFour(Token, code);
    }

    @GetMapping("test")
    public void test() {
        sendWxWorkUtil.sendAppoint(6);
    }

    /*
     * 查询原订单地址
     * */
    @GetMapping("/getOrderAddress")
    public Result getOrderAddress(@RequestParam String order_code) {
        return afterSaleService.getOrderAddress(order_code);
    }

    /*
     * 录入补发快递单
     * */
    @GetMapping("/enterReissue")
    public Result enterReissue(@RequestParam String code, @RequestParam String tracking_code) {
        return afterSaleService.enterReissue(code, tracking_code);
    }

}
